﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nop.Core.Infrastructure;
using Nop.Services.Logging;
using Nop.Services.Tasks;
using Nop.Core.Caching;
using Nop.Services.Cms;
using Nop.Services.Configuration;
using Nop.Plugin.Widgets.EKomi.Models;
using Nop.Data;
using Nop.Core.Plugins;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using Nop.Services.Stores;
using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Plugin.Widgets.EKomi.Services;

namespace Nop.Plugin.Widgets.EKomi
{
    public partial class RefreshFeedbackTask : ITask
    {

        #region Fields

        private readonly ISettingService _settingService;
        private readonly ICacheManager _cacheManager;
        private readonly Regex _regex;

        #endregion

        #region Ctor

        public RefreshFeedbackTask(ISettingService settingService,
            ICacheManager cacheManager)
        {
            this._settingService = settingService;
            this._cacheManager = EngineContext.Current.ContainerManager.Resolve<ICacheManager>("nop_cache_static");
            System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline)
                | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            _regex = new Regex("(?:^|,)(\\\"(?:[^\\\"]+|\\\"\\\")*\\\"|[^,]*)", options);
        }

        #endregion
        
        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {

            var pluginFinder = EngineContext.Current.Resolve<IPluginFinder>();
            var logger = EngineContext.Current.Resolve<ILogger>();
            var _dbContext = EngineContext.Current.Resolve<IDbContext>();
            try
            {


                //is plugin installed?
                var pluginDescriptor = pluginFinder.GetPluginDescriptorBySystemName("Widgets.EKomi");
                if (pluginDescriptor == null || !pluginDescriptor.Installed)
                    return;

                var _eKomiService = EngineContext.Current.Resolve<IEKomiService>();
                _eKomiService.GetAll(true);



            }
            catch (System.Exception ex)
            {
                logger.Error("EKomi gift card desactivation task failed", ex);
            }

        }



     
    }
}

